﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Comment_Index.aspx.cs" Inherits="ncp.Web.cms.work.CommentManager.Comment_Index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css" />
    <link href="../../css/base.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../../js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../js/common.js"></script>
<style type="text/css">
.previewbox
{
	background-color:#fff;
	width: 300px;
}
#contactPre
{
	padding:10px;
}
</style>
</head>
<body style="margin:0; padding:0px;">
<form id="form1" runat="server">
    <div>
        <div class="toolbar" style="background-color:#efefef">
	        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-remove" onclick="onDeleteNews();">删除</a>&nbsp;
            <span>查询条件:</span>
            <select id="ddlQuery">
                <option value="Product_Title">产品名称</option>
                <option value="Comment_Note">评论内容</option>
                <option value="Comment_Date">发布时间</option>
                <option value="Client_Name">评论者</option>
            </select>
            <select name="ddlOperator" id="ddlOperator">
                <option value="like">包含</option>
                <option value="=">等于</option>
                <option value=">">大于</option>
                <option value="&lt;">小于</option>
            </select>
            <input name="txtQuery" type="text" id="txtQuery" style="width:80px;" />
	        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="onSearch()">查询</a>
        </div>
        <div id="divright">    
        </div>

	    <div class="previewbox">
	    <span title="关闭" onclick="hidePreview()" class="imgdelete"></span>
	    <div id="contactPre"></div>
	</div>
	</div>
	</form>
</body>
</html>
<%--商品信息--%>
<script type="text/javascript">
    var pageobj = new Object();
    //初始化
    $(function() {
        initPageObj();
        initDatagrid();
        onSearch();
        bindClick();
    });

   
    //初始化页码对象
    function initPageObj() {
        pageobj.currentpageindex = 1;
        pageobj.pagesize = 10;
        pageobj.sorting = "Product_Id";
        pageobj.sortdir = "asc";
        pageobj.currentwhere = GetstrWhere();
        pageobj.recordcount = GetRecordCount();
    }

    //初始化表格
    function initDatagrid() {
        $('#divright').datagrid({
            height: $(window).height() - 61,
            nowrap: true,
            striped: true,
            singleSelect: true,
            sortName: 'Product_Id',
            sortOrder: 'asc',
            remoteSort: false,
            idField: 'Comment_Id',
            pagination: true,
            rownumbers: true,
            columns: [[
					{ field: 'Product_Title', title: '产品名称', sortable: 'true', width: 200 },
					{ field: 'Comment_Note', title: '评论内容', sortable: 'false', width: 300,
					    formatter: function(val, rec) {
					    return "<a href=\"javascript:void(0);\" commentId=\"" + rec.Comment_Id + "\" class=\"cliContact\">查看评论</a>";
					    }
					},
					{ field: 'Comment_Date', title: '评论时间', sortable: 'true', width: 130 },
					{ field: 'Client_Name', title: '评论者', sortable: 'true', width: 60, align: 'center' },
					{ field: 'Comment_Status', title: '状态', sortable: 'true', width: 60, align: 'center',
					    styler: function(value, row, index) {
					        if (value == '0') {
					            return 'background-color:#6293BB;color:#fff;font-weight:bold;';
					        }
					    },
					    formatter: function(value, rec) {
					        if (value == '0') {
					            return '禁用';
					        }
					        else {
					            return '启用';
					        }
					    }
					},
					{ field: 'Comment_Id', title: '操作', sortable: 'true', width: 60, align: 'center',
					    formatter: function(value, rec, rowIndex) {
					        if (rec.Comment_Status == '0')
					            return "<a href=\"#\" class=\"easyui-linkbutton\" onclick=\"onSeting(" + rowIndex + "," + value + ",1);\">启用</a>";
					        else
					            return "<a href=\"#\" class=\"easyui-linkbutton\" onclick=\"onSeting(" + rowIndex + "," + value + ",0);\">禁用</a>";
					    }
					}
				]]
        });
    }


    function bindClick() {
        $(".cliContact").click(function(e) {
            $("#contactPre").html(getContent($(this).attr("commentId")));
            $(".previewbox").css({ "top": e.pageY + 10, "left": e.pageX - 190 });
            $(".previewbox").fadeIn();
        });
    }
    
    function hidePreview() {
        $('.previewbox').fadeOut();
    }
    
    function getContent(commentId) {
        var rep = ncp.Web.cms.work.CommentManager.Comment_Index.GetContent(commentId);
        if (rep.value != null) {
            var jsonOBJ = eval(rep.value)[0];
            if (jsonOBJ.isreload) {
                return jsonOBJ.msg;
            } else {
                return "";
            }
        }
        return "";
    }
    
    function initPager() {
        var p = $('#divright').datagrid('getPager');
        $(p).pagination({
            total: pageobj.recordcount,
            pageSize: pageobj.pagesize,
            pageList: [10, 15, 20, 25, 30],
            showRefresh: true,
            showPageList:true,
            beforePageText: '第',
            afterPageText: '页 共 {pages} 页',
            displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
            onSelectPage: function(pageNumber, pageSize) {
                $(this).pagination('loading');
                onShowPageNo(pageNumber, pageSize);
                $(this).pagination('loaded');
            }
        });
    }
    
    //翻页
    function onShowPageNo(pageNumber, pageSize) {
        pageobj.pagesize = pageSize;
        pageobj.currentpageindex = pageNumber;
        LoadNewsInfo();
        initPager();
        return false;
    }

    //得到条件
    function GetstrWhere() {
        var response = ncp.Web.cms.work.CommentManager.Comment_Index.GetstrWhere($("#ddlQuery").val(), $("#ddlOperator").val(), $.trim($("#txtQuery").val()));
        if (response.value != null) {
            return response.value;
        }
        else
            return "";
    }
    
    //得到总记录数
    function GetRecordCount() {
        var response = ncp.Web.cms.work.CommentManager.Comment_Index.GetRecordCount(pageobj.currentwhere);
        if (response.value != null) {    
            return response.value;
        }
        else
            return 0;
    }

    //查询
    function onSearch() {
        pageobj.currentpageindex = 1;
        var key = $("#keys").val();
        pageobj.recordcount = GetRecordCount(key);
        LoadNewsInfo(key);
        initPager();
        bindClick();
        return false;
    }

    //装载商品信息视图
    function LoadNewsInfo() {
        var jsonStr = $.objectToJson(pageobj);
        var response = ncp.Web.cms.work.CommentManager.Comment_Index.BindTable(jsonStr);
        if (response.value != null) {
            var data = eval(response.value);
            $('#divright').datagrid('loadData', data);
        }
    }

    //启用/禁用评论
    function onSeting(rowIndex, Comment_Id, Comment_Status) {
        $('#divright').datagrid('selectRow', rowIndex);
        var selected = $('#divright').datagrid('getSelected');
        if (User_Status == 1) var str = "启用";
        else var str = "禁用";
        if (confirm("您确定要" + str + "吗？")) {
            var response = ncp.Web.cms.Client_List.UpdateCommentStatus(Comment_Id, Comment_Status);
            if (response.value != null) {
                var jsonOBJ = eval(response.value)[0];
                selected.Comment_Status = Comment_Status;
                $('#divright').datagrid('refreshRow', rowIndex);
                alert(jsonOBJ.msg);
            }
        }
        return false;
    }

    //删除评论
    function onDeleteNews() {
        var selected = $('#divright').datagrid('getSelected');
        if (selected) {
            if (confirm("您确定要删除吗？")) {
                var response = ncp.Web.cms.work.CommentManager.Comment_Index.DeleteNewsInfo(selected.Comment_Id);
                if (response.value != null) {
                    var jsonOBJ = eval(response.value)[0];
                    if (jsonOBJ.isreload) {
                        var index = $('#divright').datagrid('getRowIndex', selected);
                        $('#divright').datagrid('deleteRow', index);
                        $('#divright').datagrid('clearSelections');
                    }
                    alert(jsonOBJ.msg);
                }
            } 
        }
        else
            alert("请先选择一条记录！");
        return false;
    }
</script>